# _*_ coding：UTF-8 _*_
# @Time：2021/9/414:34
# @Author：JYZ
# @Project：oneWork

import urllib.request
import urllib.parse


# 爬取地址
url = "https://movie.douban.com/j/chart/top_list?type=5&interval_id=100%3A90&action=&start=0&limit=20"

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"}

# 请求对象定制
request = urllib.request.Request(url=url, headers=headers)

# 获取响应数据
response = urllib.request.urlopen(request)

# 数据解码
content = response.read().decode("utf-8")

# 默认使用GBK 编码 若内容中有中文 使用 encoding="utf-8" 编码格式
fp = open("data.json", "w", encoding="utf-8")
fp.write(content)
fp.close()